/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.Random;

/**
 * <p>Project: javaseapp - Arr4
 * <p>Powered by webrx On 2021-08-04 09:49:29
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class Arr5 {
    public static void main(String[] args) {
        //冒泡排序
        Random rand = new Random();

        int[] nums = new int[10];

        for (int i = 0; i < nums.length; i++) {
            nums[i] = rand.nextInt(100) + 1;
        }

        //排序前遍历输出
        print(nums);

        //冒泡
        for (int i = 0; i < nums.length - 1; i++) {
            for (int j = 0; j < nums.length - 1 - i; j++) {
                //> 升序   < 降序
                if (nums[j] < nums[j + 1]) {
                    int t = nums[j];
                    nums[j] = nums[j + 1];
                    nums[j + 1] = t;
                }
            }
        }

        //排序后
        print(nums);

    }

    public static void print(int[] a) {
        for (int i : a) {
            System.out.printf("%d ", i);
        }
        System.out.println();
    }
}
